package com.argrace.smart.glide;


import android.content.Context;

import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool;
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.module.AppGlideModule;

import java.io.InputStream;


/**
 * Created by Elune on 2016/12/6.
 */

//@GlideModule
public class GlideConfigModule extends AppGlideModule  {
    public final static String TAG = "GlideConfigModule";


    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
//        builder.setMemoryCache(new LruResourceCache(10 * 1024 * 1024));
        //缓冲池
        builder.setDiskCache(new InternalCacheDiskCacheFactory(context, GlideConfigConstants.MAX_CACHE_DISK_SIZE));
        //内存大小
        builder.setMemoryCache(new LruResourceCache(GlideConfigConstants.MAX_CACHE_MEMORY_SIZE));
        //图片池
        builder.setBitmapPool(new LruBitmapPool(GlideConfigConstants.MAX_CACHE_MEMORY_SIZE));

    }

    @Override
    public void registerComponents(Context context, Registry registry) {
//        registry.append(Api.GifResult.class, InputStream.class, new GiphyModelLoader.Factory());

        registry.append(String.class, InputStream.class,new CustomBaseGlideUrlLoader.Factory());
    }


    /**
     * 清单解析的开启
     *
     * 这里不开启，避免添加相同的modules两次
     * @return
     */
    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }

}